# == Schema Information
# Schema version: 4
#
# Table name: users
#
#  id                        :integer         not null, primary key
#  email                     :string(255)     
#  crypted_password          :string(40)      
#  salt                      :string(40)      
#  created_at                :datetime        
#  updated_at                :datetime        
#  remember_token            :string(255)     
#  remember_token_expires_at :datetime        
#

class User < ActiveRecord::Base
  include AuthenticatedBase
  
  has_many :participations, :as => 'participant'
  
  has_many :events
  has_many :created_organizations, :through => :participations, :source => 'participable', :conditions => 'participations.participant_role = "owner"'

  # prevents a user from submitting a crafted form that bypasses activation
  # anything else you want your user to change should be added here.
  attr_accessible :email, :password, :password_confirmation
  
  def owned_organizations
    participations.find(:all, :conditions => "participable_type = 'Organization' AND participant_role = 'owner'")
  end
  
  def administrated_organizations
    participations.find(:all, :conditions => "participable_type = 'Organization' AND participant_role = 'administrator'")
  end  
  
  def participated_organizations
    participations.find(:all, :conditions => "participable_type = 'Organization' AND participant_role = 'participant'")
  end
end
